package com.sicheng.lc.周赛.分类.模拟;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/23 9:37
 */
public class 转化时间需要的最少操作数 {

    //    https://leetcode.cn/problems/minimum-number-of-operations-to-convert-time/
    public int convertTime(String current, String correct) {

        int t = getMinit(correct) - getMinit(current);
        int res = 0;
        while (t >= 60) {
            t -= 60;
            res++;
        }

        while (t >= 30) {
            t -= 30;
            res++;
        }
        while (t >= 15) {
            t -= 15;
            res++;
        }

        while (t >= 5) {
            t -= 5;
            res++;
        }

        return res + t;
    }

    private int getMinit(String s) {
        int h = 0;
        int i = 0;
        for (; i < s.length(); i++) {
            if (s.charAt(i) == ':') {
                break;
            }
            h = h * 10 + s.charAt(i) - '0';
        }
        int m = 0;
        for (; i < s.length(); i++) {
            m = m * 10 + s.charAt(i) - '0';
        }

        return h * 60 + m;
    }
}
